package net.googlecode.demenkov.utils;

import net.googlecode.demenkov.domains.Person;

import java.util.Comparator;

/**
 * Comparator-class that compare persons by name
 *
 * @author Demenkov Yura
 */
public class PersonComparatorByName implements Comparator<Person> {
    @Override
    public int compare(Person o1, Person o2) {
        if (o1.getLastName().compareToIgnoreCase(o2.getLastName()) != 0) {
            return (o1.getLastName().compareToIgnoreCase(o2.getLastName()));
        } else {
            if (o1.getFirstName().compareToIgnoreCase(o2.getFirstName()) != 0) {
                return (o1.getFirstName().compareToIgnoreCase(o2.getFirstName()));
            } else {
                return o1.getMiddleName().compareToIgnoreCase(o2.getMiddleName());
            }
        }
    }
}
